//
//  SmsCloudTableResultCell.m

#import "SmsCloudTableResultCell.h"

static NSString * SmsCloudTableResultCellId = @"SmsCloudTableResultCellId";
@interface SmsCloudTableResultCell()
@property (nonatomic,strong) UIImageView *smsCloudImgView;
@property (nonatomic,strong) UILabel *smsCloudHeadNameLab;
@property (nonatomic,strong) UILabel *smsCloudHeadNumLab;
@end
@implementation SmsCloudTableResultCell
+ (instancetype)smsCloudTableResultCell:(UITableView *)tableView{
    SmsCloudTableResultCell * smsCloudTableResultCell = [tableView dequeueReusableCellWithIdentifier:SmsCloudTableResultCellId];
    if (!smsCloudTableResultCell) {
        smsCloudTableResultCell = [[SmsCloudTableResultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SmsCloudTableResultCellId];
    }
    smsCloudTableResultCell.backgroundColor = [UIColor clearColor];
    smsCloudTableResultCell.selectionStyle = UITableViewCellSelectionStyleNone;
    smsCloudTableResultCell.accessoryType = UITableViewCellAccessoryNone;
    return smsCloudTableResultCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self smsCloudInitView];
    }
    return self;
}
- (void)smsCloudInitView{
    UIView * smsCloudBgView = [[UIView alloc] init];
    smsCloudBgView.backgroundColor = [SmsCloudHead SmsCloudColorHexString:@"#E6F5FF"];
    smsCloudBgView.layer.cornerRadius = [SmsCloudHead SmsCloudScreewRatio:16];
    smsCloudBgView.clipsToBounds = YES;
    [self.contentView addSubview:smsCloudBgView];
    [smsCloudBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:24]));
        make.right.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:24]));
        make.top.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.bottom.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:20]));
    }];
    self.smsCloudImgView = [[UIImageView alloc] init];
    [smsCloudBgView addSubview:self.smsCloudImgView];
    [self.smsCloudImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:50]));
        make.centerY.equalTo(smsCloudBgView);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:88]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:88]));
    }];
    self.smsCloudHeadNameLab = [[UILabel alloc] init];
    self.smsCloudHeadNameLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:30] weight:UIFontWeightRegular];
    self.smsCloudHeadNameLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#262729"];
    [smsCloudBgView addSubview:self.smsCloudHeadNameLab];
    [self.smsCloudHeadNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.smsCloudImgView.mas_right).offset([SmsCloudHead SmsCloudScreewRatio:19]);
        make.top.equalTo(self.smsCloudImgView).offset([SmsCloudHead SmsCloudScreewRatio:3]);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:42]));
    }];
    self.smsCloudHeadNumLab = [[UILabel alloc] init];
    self.smsCloudHeadNumLab.font = [UIFont systemFontOfSize:[SmsCloudHead SmsCloudScreewRatio:24] weight:UIFontWeightMedium];
    self.smsCloudHeadNumLab.textColor = [SmsCloudHead SmsCloudColorHexString:@"#08C161"];
    [smsCloudBgView addSubview:self.smsCloudHeadNumLab];
    [self.smsCloudHeadNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.smsCloudHeadNameLab);
        make.top.equalTo(self.smsCloudHeadNameLab.mas_bottom).offset([SmsCloudHead SmsCloudScreewRatio:6]);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:34]));
    }];
    UIImageView * smsCloudGoImgView = [[UIImageView alloc] init];
    smsCloudGoImgView.image = [SmsCloudHead SmsCloudImageNamed:@"smsCloudHomeGo"];
    [smsCloudBgView addSubview:smsCloudGoImgView];
    [smsCloudGoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:37]));
        make.centerY.equalTo(smsCloudBgView);
        make.width.equalTo(@([SmsCloudHead SmsCloudScreewRatio:198]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:66]));
    }];
    UIButton * smsCloudGobtn = [[UIButton alloc] init];
    [smsCloudGobtn addTarget:self action:@selector(smsCloudGo) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:smsCloudGobtn];
    [smsCloudGobtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
    }];
}
- (void)smsCloudGo{
    if(self.SmsCloudProductBlock){
        self.SmsCloudProductBlock(_smsCloudProductMdl);
    }
}
-(void)setSmsCloudProductMdl:(SmsCloudProductModel *)smsCloudProductMdl{
    _smsCloudProductMdl = smsCloudProductMdl;
    if(_smsCloudProductMdl){
        self.smsCloudHeadNameLab.text = _smsCloudProductMdl.name;
        [self.smsCloudImgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.ydl.cool/img/static/sms/%@0.webp",_smsCloudProductMdl.code]] placeholderImage:[SmsCloudHead SmsCloudImageNamed:@"smsCloudLogo"]];
        self.smsCloudHeadNumLab.text = [NSString stringWithFormat:@"今日注册%@+",_smsCloudProductMdl.num];
    }
}
@end
